package com.ssyt.ec.sys.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ssyt.ec.common.AppServlet;
import com.ssyt.ec.common.util.DBUtil;
import com.ssyt.ec.common.util.FastjsonUtil;
import com.ssyt.ec.sys.entity.assitdbEntity;

@WebServlet("/AssitdbServlet")
public class AssitdbServlet extends AppServlet {
	
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String command = request.getParameter("command");
		if ("listAssitdb".equals(command)) {
			listAssitdb(request, response);
		} else if ("deleteAssitdb".equals(command)) {
			deleteAssitdb(request, response);
		} 
	}
	
	/**
	 * 查询备份数据信息
	 * 
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	private void listAssitdb(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		
		List<assitdbEntity> asssitdb = DBUtil.executeQuery(assitdbEntity.class,
				"SELECT db.*,us.name AS 'user__name' FROM  assit_db_data db,sys_user us WHERE db.operate_user_id=us.id");
		print(response, FastjsonUtil.toJson(asssitdb));
	}
	
	 /**
	  * 删除备份数据信息
	  */
	 private void deleteAssitdb(HttpServletRequest request,
			 HttpServletResponse response) throws IOException {
	        
		 String ids = request.getParameter("ids");
	        int row = DBUtil.executeUpdate("DELETE FROM assit_db_data WHERE id IN (" + ids + ")");

	        if (row >= 1) {
	            print(response, 1);
	       }
	 }
}
